package com.fhz.day009;

import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.work.Data;
import androidx.work.Worker;
import androidx.work.WorkerParameters;

/**
 * 时间:2022/5/27
 *
 * @author msfeng
 * 简述: TODO
 */
public class UploadWorker extends Worker {

    private static final String TAG = "feng";
    private static final String PROGRESS = "PROGRESS";
    private static final long DELAY = 1000L;
    public UploadWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
        super(context, workerParams);
        setProgressAsync(new Data.Builder().putInt(PROGRESS, 0).build());
    }
    boolean falg = true;
    @NonNull
    @Override
    public Result doWork() {
        setProgressAsync(new Data.Builder().putInt(PROGRESS, 100).build());
        try {
            // Doing work.
            Thread.sleep(DELAY);
        } catch (InterruptedException exception) {
            // ... handle exception
        }
        String imageUriInput = getInputData().getString("IMAGE_URI");
        Log.i(TAG, "doWork: "+imageUriInput);
        if(falg){
            return Result.success();
        }else{
            return Result.retry();
        }
    }
}

